package com.hxd.otc.module.order.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hxd.otc.R;
import com.hxd.otc.module.order.activity.SaleOrderDetailActivity;
import com.hxd.otc.module.order.bean.AllOrderBean;
import com.hxd.otc.utils.CommonUtil;
import com.hxd.otc.utils.DateUtil;
import com.hxd.otc.utils.ResourceUtil;
import com.hxd.otc.utils.StringUtil;
import com.hxd.otc.utils.UIUtils;
import com.hxd.otc.widget.BlocksToast;

/**
 * 作  者 :  zjl
 * 时  间 :  2018/6/5 18:03
 * 描  述 :  ${全部订单页面}
 */
public class AllOrderAdapter extends BaseQuickAdapter<AllOrderBean.DataBean, BaseViewHolder> {

    public boolean isNor;

    public void setNor(boolean nor) {
        isNor = nor;
    }

    public AllOrderAdapter() {
        super(R.layout.adapter_all_order, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, final AllOrderBean.DataBean item) {

        helper.setText(R.id.tv_order_number, UIUtils.getContext().getString(R.string.order_number, item.subOrderId));
        helper.setText(R.id.tv_name, item.getAskNickName());
        helper.setText(R.id.tv_money, UIUtils.getContext().getString(R.string.deal_account,
                StringUtil.format8Number(item.totalPrice), item.supportCurrencyCode));
        helper.setText(R.id.tv_time, DateUtil.format(item.createDate, DateUtil.YY_MM_DD_HH_MM_SS));
        helper.setText(R.id.tv_sale_type, UIUtils.getContext().getString(item.exType.equals("1") ? R.string.order_sale : R.string.order_buy) + item.symbol);
        if (item.askUserId.equals(item.orderUserId)) {
            helper.setGone(R.id.iv_sliver, true);
        } else {
            helper.setGone(R.id.iv_sliver, false);
        }
        helper.setTextColor(R.id.tv_sale_type, ResourceUtil.getColor(R.color.color_FF464E5F));
        helper.setTextColor(R.id.tv_name, ResourceUtil.getColor(R.color.color_FF464E5F));
        helper.setTextColor(R.id.tv_money, ResourceUtil.getColor(R.color.color_FF464E5F));
        switch (item.status) {
            case SaleOrderDetailActivity.SALE_UNPAID:
                helper.setTextColor(R.id.tv_statues, UIUtils.getContext().getResources().getColor(R.color.color_FFFF7766));
                helper.setText(R.id.tv_statues, UIUtils.getContext().getString(R.string.order_un_pay));
                helper.setImageResource(R.id.iv_sliver, R.mipmap.order_trading_v_icon);
                if (isNor) {
                    helper.setText(R.id.tv_pay_state, !item.exType.equals("0") ?
                            UIUtils.getContext().getString(R.string.the_other_party_has_not_yet_paid)
                            : UIUtils.getContext().getString(R.string.not_confirmed_payment));
                } else {//广告商订单买卖相反：0.买入,1.卖出
                    helper.setText(R.id.tv_pay_state,  !item.exType.equals("0") ?
                            UIUtils.getContext().getString(R.string.not_confirmed_payment)
                            : UIUtils.getContext().getString(R.string.the_other_party_has_not_yet_paid));
                }
                break;

            case SaleOrderDetailActivity.SALE_PAYED://广告商订单买卖相反：0.买入,1.卖出
                helper.setTextColor(R.id.tv_statues, UIUtils.getContext().getResources().getColor(R.color.color_FF5AC792));
                helper.setText(R.id.tv_statues, UIUtils.getContext().getString(R.string.order_pay));
                helper.setImageResource(R.id.iv_sliver, R.mipmap.order_trading_v_icon);
                if (isNor) {
                    helper.setText(R.id.tv_pay_state, !item.exType.equals("0") ?
                            UIUtils.getContext().getString(R.string.please_confirm_the_payment)
                            : UIUtils.getContext().getString(R.string.waitint_the_other_confirm_the_payment));
                } else {
                    helper.setText(R.id.tv_pay_state,  !item.exType.equals("0")?
                            UIUtils.getContext().getString(R.string.waitint_the_other_confirm_the_payment)
                            : UIUtils.getContext().getString(R.string.please_confirm_the_payment)
                    );
                }
                break;

            case SaleOrderDetailActivity.SALE_REPRESENTATION:
                helper.setTextColor(R.id.tv_statues, UIUtils.getContext().getResources().getColor(R.color.color_FFFF7766));
                helper.setText(R.id.tv_statues, UIUtils.getContext().getString(R.string.order_appeal));
                helper.setText(R.id.tv_pay_state, UIUtils.getContext().getString(R.string.order_appealing));
                helper.setImageResource(R.id.iv_sliver, R.mipmap.order_trading_v_icon);
                break;

            case SaleOrderDetailActivity.SALE_CANCLED:
                helper.setTextColor(R.id.tv_statues, UIUtils.getContext().getResources().getColor(R.color.color_FF95A2AC));
                helper.setText(R.id.tv_statues, UIUtils.getContext().getString(R.string.order_cancle));
                helper.setText(R.id.tv_pay_state, UIUtils.getContext().getString(R.string.order_cancelled));
                helper.setImageResource(R.id.iv_sliver, R.mipmap.order_cancle_trading_v_icon);
                helper.setTextColor(R.id.tv_sale_type, ResourceUtil.getColor(R.color.color_FF95A2AC));
                helper.setTextColor(R.id.tv_name, ResourceUtil.getColor(R.color.color_FF95A2AC));
                helper.setTextColor(R.id.tv_money, ResourceUtil.getColor(R.color.color_FF95A2AC));
                break;

            case SaleOrderDetailActivity.SALE_FINISHED:
                helper.setTextColor(R.id.tv_statues, UIUtils.getContext().getResources().getColor(R.color.color_DefaultButton));
                helper.setText(R.id.tv_statues, UIUtils.getContext().getString(R.string.order_completed));
                helper.setText(R.id.tv_pay_state, UIUtils.getContext().getString(R.string.order_finished_hint));
                helper.setImageResource(R.id.iv_sliver, R.mipmap.order_trading_v_icon);
                break;
        }

        helper.getView(R.id.tv_order_number).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommonUtil.copyData(item.subOrderId);
                BlocksToast.get().showToast(UIUtils.getContext().getString(R.string.copy_number_hint));
            }
        });
    }
}
